/*
 * Frame.java
 * @author Andrey Tesler
 * Created for DiffView project
 * Created on 4 October 2009, 13:55
 */

package diffview.gui;

import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.lang.System.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import static diffview.Main.createModel;

public class Frame extends JFrame {
    
    ViewDomain viewDomain;
    
    Action openAction = new AbstractAction("Choose files to open") {
        public void actionPerformed(ActionEvent ev) {
            open();
        }
    };
    
    public Frame() {
        super("DiffView");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());
        add(viewDomain = new ViewDomain(), BorderLayout.NORTH);
        add(new JButton(openAction), BorderLayout.SOUTH);
        setSize(800, 600);
        setVisible(true);
    }
    
        
    public void open() {
        OpenDialog openDialog = new OpenDialog(this);
        openDialog.setVisible(true);
        String oldFileName = openDialog.getResults()[0];//getOldFileName();
        String newFileName = openDialog.getResults()[1];//getNewFileName();
        try {
            viewDomain.setModel(diffview.Main.createModel
                    (oldFileName, newFileName));
            viewDomain.repaint();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this,
                    ex.getLocalizedMessage(), 
                    "Error", 
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    
}
